﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using AjaxChatService.FacebookMessenger;
using AjaxChatService.Models;

namespace AjaxChatService.Controllers
{
    [HttpHeader("Access-Control-Allow-Origin", "*")]
    public class FBMessagesController : ApiController
    {
        private FacebookUtils _helper = new FacebookUtils();

        // GET api/fbmessages
        public IEnumerable<FBMessage> Get()
        {
            List<FBMessage> messages = XmppClientConnections.messages;
            XmppClientConnections.messages = new List<FBMessage>();
            //XmppClientConnections.messages.Clear();
            return messages;
        }

        // POST api/fbmessages
        public HttpResponseMessage PostMessage(FBMessage message)
        {
            if (_helper.Send_Click(message))
            {
                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }

        // PUT api/fbmessages/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/fbmessages/5
        public void Delete(int id)
        {
        }
    }
}
